﻿using Somnus.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Somnus.Services.Data
{
    public class DBOperation
    {
        private static SqlConnection _conn;

        static DBOperation()
        {
            _conn = new SqlConnection(@"Data Source=SOMNUSV-VAIO;Integrated Security=True;DataBase=WiFiAPDB");

        }
        public static bool InsertNewRecord(WirelessAP ap)
        {
            
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = @"INSERT INTO APINFO VALUES (@ssid,@mac,@level,@posx,@posy,@gid)";
            cmd.Connection = _conn;
            cmd.Parameters.Add(new SqlParameter("@ssid",ap.ssid));
            cmd.Parameters.Add(new SqlParameter("@mac",ap.mac));
            cmd.Parameters.Add(new SqlParameter("@level", ap.level));
            cmd.Parameters.Add(new SqlParameter("@posx",ap.posX));
            cmd.Parameters.Add(new SqlParameter("@cury",ap.posY));
            cmd.Parameters.Add(new SqlParameter("@gid",ap.gid));
            _conn.Open();
            cmd.ExecuteNonQuery();
            _conn.Close();
            return true;
            
        }
        public static WirelessAP GetMostRelativeRecord(WirelessAP ap)
        {
            return new WirelessAP { ssid = "name", level = 1, posX = 1, posY = 0, gid = 0, mac="7dceaa4d5f6a" };
        }

    }
}